// pages/list/list.js
const http = require("../../utils/http.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    seasonArr: [],
    endtype: false,
    count:"",
  },

  //定义自定义数据
  customData:{
    page:1,
  },
  //  获取数据
  getData(){
      //获取数据
      http.request("requirement/request/getMatchedProducts", {
        curPagePath: "/wx/customer/classic/search.html?pageid=0piQDrywbusu9y3CXGJj",
        keyWord: this.data.count,
        pageNow: this.customData.page,
        pageSize: 10,
        product_type: 1
      }, "post").then(res => {
        console.log(res.data.matchedProducts);
        this.setData({
          seasonArr: res.data.matchedProducts
        });
      })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({count:options.searchKey});
    this.getData();
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.getData();
    //停止下拉
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (!this.data.endtype) {
      // this.setData({
      //   page: this.data.page + 1
      // });
      this.customData.page++;
      http.request("requirement/request/getMatchedProducts", {
        curPagePath: "/wx/customer/classic/search.html?pageid=0piQDrywbusu9y3CXGJj",
        keyWord: this.data.count,
        pageNow: this.customData.page,
        pageSize: 10,
        product_type: 1
      }, "post").then(res => {
        console.log(res.data.matchedProducts);
        const data = res.data.matchedProducts;
        if (data.length == 0) {
          this.setData({
            endtype: true
          })
        } else {
          const oldData = this.data.seasonArr;
          const newData = oldData.concat(data);
          this.setData({
            seasonArr: newData
          });
        }
      })
    }
  }
})